<template>
    <component :is="svgComponent" :style="iconStyle" />
</template>

<script setup lang="ts" name="SvgIcon">
import { computed, onMounted, shallowRef } from 'vue';
const props = defineProps({
    name: {
        type: String,
        required: true
    },
    width: {
        type: [Number, String],
        default: 24
    },
    height: {
        type: [Number, String],
        default: 24
    },
    color: {
        type: String,
        default: 'currentColor'
    }
});

const svgComponent = shallowRef(null);

const loadSvg = async () => {
    const svgModule = await import(`@/assets/icons/${props.name}.svg`);
    svgComponent.value = svgModule.default;
};

onMounted(() => {
    loadSvg();
});

const iconStyle = computed(() => ({
    width: `${props.width}px`,
    height: `${props.height}px`,
    fill: props.color
}));
</script>

<style scoped></style>